<template>
  <div style="margin-bottom: 10px;">
    <a-input-search
      placeholder="input search text"
      style="width: 500px;"
      @search="onSearch"
    />
    <a-button type="primary" style="margin-left: 20px;" @click="toAeroAddView(currentUser.id)">添加</a-button>
  </div>
  
  <a-table :columns="columns" :data-source="aeroDatas" :scroll="{ y: 400 }"  >
    <template #bodyCell="{ column ,record}">
      <template v-if="column.key === 'operation'">
        <a @click="toAeroUpdateView(record.id)">修改</a>
        <a @click="deleteAeroData(record)" style="padding-left: 3px;">删除</a>
      </template>
    </template>
  </a-table> 

  
</template>

<script setup>
import { ref ,onMounted} from 'vue';
import axios from '../config/axios.ts'
import {useRouter,useRoute }from 'vue-router'
import { message } from 'ant-design-vue';

const route = useRoute();
const router = useRouter();





const columns = [
  { title: 'id',                    dataIndex: 'id',                     key: 'id', fixed: 'left' ,width:70},
  { title: '数据类型',              dataIndex: 'dtype',                  key: 'dtype', fixed: 'left' ,width:70},
  { title: '攻角(°)',               dataIndex: 'alf',                    key: '1',  width:70},
  { title: '舵偏角',                dataIndex: 'angleDeflectionFlaps',   key: '2', width:70 },
  { title: '侧滑角(°)',             dataIndex: 'beta',                   key: '3',  width:70},
  { title: '参考展长',              dataIndex: 'bref',                   key: '4', width:70 },
  { title: '坐标系系统',            dataIndex: 'coordinateSystem',       key: '5',  width:70},
  { title: '坐标系',                dataIndex: 'coordinate',             key: '6',  width:70},
  { title: '副翼舵偏角',            dataIndex: 'da',                    key: '7', width:70 },
  { title: '升降舵偏角',            dataIndex: 'de',                      key: '9' ,width:70},
  { title: '方向舵偏角',            dataIndex: 'dr',                    key: '10' ,width:70},
  { title: '油气化学恰当比',        dataIndex: 'fst',                     key: '11' ,width:70},
  { title: '来流比热比',            dataIndex: 'gamma',                   key: '12' ,width:70},
  { title: '参考长度',              dataIndex: 'lref',                   key: '13' ,width:70},
  { title: '马赫数',                dataIndex: 'ma',                     key: '14',width:70 },
  { title: '来流静压',              dataIndex: 'p',                      key: '15' ,width:70},
  { title: '油气比',                dataIndex: 'ph',                     key: '16' ,width:70},
  { title: '动压(pa)',            dataIndex: 'q',                        key: '17' ,width:70},
  { title: '来流总压',            dataIndex: 'pt',                       key: '18' ,width:70},
  { title: '雷诺数',               dataIndex: 're',                      key: '19' ,width:70},
  { title: '参考面积',            dataIndex: 'sref',                     key: '20' ,width:70},
  { title: '来流静温',            dataIndex: 't',                        key: '21' ,width:70},
  { title: '来流总温',            dataIndex: 'tt',                       key: '22' ,width:70},
  { title: '来流速度',            dataIndex: 'u',                        key: '23' ,width:70},
  { title: '用户id',              dataIndex: 'userId',                   key: '24' ,width:70},
  {
    title: '操作',
    key: 'operation',
    fixed: 'right',
    width: 100,
  },
];




onMounted(()=>{
  getAeroDatas()
  getLoginUser()
})
const aeroDatas = ref()
const currentUser = ref()

//获取全部的气动数据并展示
const getAeroDatas =async()=>{
  const result = await axios.get("/aero/all")
  aeroDatas.value = result.data.data.filter(item=>item.isDelete === 0)
}
//跳转到添加页面，添加数据
const toAeroAddView = (id)=>{
  router.push({
    path:'/aero/add',
    query:{
      userId:id
    }
  })
}
//获取当前登录的用户
const getLoginUser =async()=>{
  const reslut = await axios.get("/user/get/login")
  currentUser.value = reslut.data.data
}

//跳转到修改数据页面
const toAeroUpdateView = (id)=>{
  router.push({
    path:'/aero/update',
    query:{
      aeroDataId:id
    }
  })
}

const deleteAeroData = async(aerodata)=>{
  await axios.post('/aero/delete',aerodata)
  message.success("删除成功")
  location.reload()
}

const test = (a)=>{
  console.log(a);
}
//todo
const onSearch = ()=>{
  alert("serach")
}
</script>
